import {createAction} from "redux-actions";
import {call, put} from "redux-saga/effects";
import {getDoctor} from "../../../utils/RequestUtils";
import {DOCTOR_EXPAND_ITEM, DOCTOR_LIST, DOCTOR_LIST_FETCH} from "../../types";

// 获取科室列表
const doctorList = createAction(DOCTOR_LIST, (data: []) => {
    return {data};
});

// const doctorListFetch = (id: string) => {
//     return (dispatch: Dispatch<AnyAction>) => {
//         dispatch(doctorList([]));
//         return getDoctor(id).then((res: AxiosResponse<[]>) => {
//             dispatch(doctorList(res.data));
//         });
//     };
// };

const doctorListFetch = createAction(DOCTOR_LIST_FETCH, (id: string) => {
        return {id};
    })
;


const doctorExpandItem = createAction(DOCTOR_EXPAND_ITEM, (id: string) => {
    return {id};
});


export function* requestDoctorList(id: string) {
    yield put(doctorList([]));
    const fetchedData = yield call(getDoctor, id);
    yield put(doctorList(fetchedData.data));
}

export {
    doctorExpandItem,
    doctorList,
    doctorListFetch
}